package Test1;

import java.io.*;
import javax.swing.*;

public class average1 {
public static void main(String[] args)throws IOException {
String studentName, t1, t2, t3, t4, t5;
double test1, test2, test3, test4, test5, average;
char grade;

FileWriter fw= new FileWriter("StudentRecords.txt", true);
PrintWriter outputFile = new PrintWriter(fw);
outputFile.println("Student, Test1, Test2, Test3, "
+ "Test4, Test5, Average, Grade");
int response = JOptionPane.showConfirmDialog(null, 
"Would you like to enter student record?",
"Confirm",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
while(response==0){
//Get student name
studentName=JOptionPane.showInputDialog("Enter student name");
//Get student's test score's
t1 = JOptionPane.showInputDialog("Enter student first test score");
test1 = Double.parseDouble(t1);
t2 = JOptionPane.showInputDialog("Enter student second test score");
test2 = Double.parseDouble(t2);
t3 = JOptionPane.showInputDialog("Enter student third test score");
test3 = Double.parseDouble(t3);
t4 = JOptionPane.showInputDialog("Enter student fourth test score");
test4 = Double.parseDouble(t4);
t5 = JOptionPane.showInputDialog("Enter student fifth test score");
test5 = Double.parseDouble(t5);
average = (test1 + test2 + test3 + test4 + test5) / 5.0;
if (average >= 90)
grade = 'A';
else if (average >= 80)
grade = 'B';
else if (average >= 70)
grade = 'C';
else if (average >= 60)
grade = 'D';
else
grade = 'F';
System.out.println("Average test score: " + average + " " + grade);
// CSV form
outputFile.println(studentName+", "+ test1 +", "+ test2 +", "+
test3 +", "+ test4 +", "+ test5 +", "+
average +", "+ grade);
response = JOptionPane.showConfirmDialog(null,
"Would you like to enter anoter student records?",
"Confirm",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);}
outputFile.close();
}
} 